/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.NamedStoredProcedureQueries;
import javax.persistence.NamedStoredProcedureQuery;
import javax.persistence.OneToMany;
import javax.persistence.ParameterMode;
import javax.persistence.StoredProcedureParameter;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Tuan Long
 */
@Entity
@Table(name = "EventLibrary")
@XmlRootElement
@NamedQueries({    
    @NamedQuery(name = "EventLibrary.findAll", query = "SELECT e FROM EventLibrary e"),
    @NamedQuery(name = "EventLibrary.findByEventId", query = "SELECT e FROM EventLibrary e WHERE e.eventId = :eventId"),
    @NamedQuery(name = "EventLibrary.findByName", query = "SELECT e FROM EventLibrary e WHERE e.name = :name"),
    @NamedQuery(name = "EventLibrary.findByDescription", query = "SELECT e FROM EventLibrary e WHERE e.description = :description"),
    @NamedQuery(name = "EventLibrary.findByEventType", query = "SELECT e FROM EventLibrary e WHERE e.eventType = :eventType"),
    @NamedQuery(name = "EventLibrary.findByTimeStart", query = "SELECT e FROM EventLibrary e WHERE e.timeStart = :timeStart"),
    @NamedQuery(name = "EventLibrary.findByTimeEnd", query = "SELECT e FROM EventLibrary e WHERE e.timeEnd = :timeEnd"),
    @NamedQuery(name = "EventLibrary.getTop10EventIdAndNameByEventType", query = "SELECT e.eventId,e.name FROM EventLibrary e WHERE e.eventType = :eventType"),
    @NamedQuery(name = "EventLibrary.getTop10EventIdAndName", query = "SELECT e.eventId,e.name FROM EventLibrary e")
})
@NamedStoredProcedureQueries({
   @NamedStoredProcedureQuery(name = "EventLibrary.fillEventsDataTable", procedureName = "sp_fillEventsDataTable"),
   @NamedStoredProcedureQuery(name = "EventLibrary.testParameter", procedureName = "sp_testParameter", parameters = { 
       @StoredProcedureParameter(name = "name",mode = ParameterMode.IN,type = String.class)}),
   @NamedStoredProcedureQuery(name = "EventLibrary.fillRegisteredTable", procedureName = "sp_fillRegisteredTable"),   
   @NamedStoredProcedureQuery(name="EventLibrary.getEventLibraryDetailsById",procedureName = "sp_getEventLibraryDetailsById",parameters = {
       @StoredProcedureParameter(name="eventId",mode=ParameterMode.IN,type=Integer.class)}),
   @NamedStoredProcedureQuery(name = "EventLibrary.totalRegistered", procedureName = "sp_TotalRegistered"),
   @NamedStoredProcedureQuery(name = "EventLibrary.totalEventType", procedureName = "sp_TotalEventType"),
   @NamedStoredProcedureQuery(name = "EventLibrary.readEventComments", procedureName = "sp_readEventComments"),
   @NamedStoredProcedureQuery(name="EventLibrary.getEventContentById",procedureName = "sp_getEventContentById",parameters = {
       @StoredProcedureParameter(name="eventID",mode=ParameterMode.IN,type=Integer.class)}),
   @NamedStoredProcedureQuery(name="EventLibrary.getUpdateEventInformationById",procedureName = "sp_getUpdateEventInformationById",parameters = {
       @StoredProcedureParameter(name="eventId",mode=ParameterMode.IN,type=Integer.class)}),
   @NamedStoredProcedureQuery(name="EventLibrary.getEventComming",procedureName = "sp_getEventComming",parameters = {
       @StoredProcedureParameter(name="day",mode=ParameterMode.IN,type=Integer.class)})
})
public class EventLibrary implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "eventId")
    private List<EventInfo> eventInfoList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "EventId")
    private Integer eventId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 200)
    @Column(name = "Name")
    private String name;

    public EventLibrary(Integer eventId, String name, String description, String eventType, Date timeStart, Date timeEnd) {
        this.eventId = eventId;
        this.name = name;
        this.description = description;
        this.eventType = eventType;
        this.timeStart = timeStart;
        this.timeEnd = timeEnd;
    }
    @Size(max = 1000)
    @Column(name = "Description")
    private String description;
    @Size(max = 100)
    @Column(name = "EventType")
    private String eventType;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TimeStart")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timeStart;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TimeEnd")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timeEnd;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "eventId")
    private Collection<EventRegistration> eventRegistrationCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "eventId")
    private Collection<EventComment> eventCommentCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "eventId")
    private Collection<EventGift> eventGiftCollection;

    public EventLibrary() {
    }

    public EventLibrary(Integer eventId) {
        this.eventId = eventId;
    }

    public EventLibrary(Integer eventId, String name, Date timeStart, Date timeEnd) {
        this.eventId = eventId;
        this.name = name;
        this.timeStart = timeStart;
        this.timeEnd = timeEnd;
    }

    public Integer getEventId() {
        return eventId;
    }

    public void setEventId(Integer eventId) {
        this.eventId = eventId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getEventType() {
        return eventType;
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public Date getTimeStart() {
        return timeStart;
    }

    public void setTimeStart(Date timeStart) {
        this.timeStart = timeStart;
    }

    public Date getTimeEnd() {
        return timeEnd;
    }

    public void setTimeEnd(Date timeEnd) {
        this.timeEnd = timeEnd;
    }

    @XmlTransient
    public Collection<EventRegistration> getEventRegistrationCollection() {
        return eventRegistrationCollection;
    }

    public void setEventRegistrationCollection(Collection<EventRegistration> eventRegistrationCollection) {
        this.eventRegistrationCollection = eventRegistrationCollection;
    }

    @XmlTransient
    public Collection<EventComment> getEventCommentCollection() {
        return eventCommentCollection;
    }

    public void setEventCommentCollection(Collection<EventComment> eventCommentCollection) {
        this.eventCommentCollection = eventCommentCollection;
    }

    @XmlTransient
    public Collection<EventGift> getEventGiftCollection() {
        return eventGiftCollection;
    }

    public void setEventGiftCollection(Collection<EventGift> eventGiftCollection) {
        this.eventGiftCollection = eventGiftCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (eventId != null ? eventId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof EventLibrary)) {
            return false;
        }
        EventLibrary other = (EventLibrary) object;
        if ((this.eventId == null && other.eventId != null) || (this.eventId != null && !this.eventId.equals(other.eventId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entities.EventLibrary[ eventId=" + eventId + " ]";
    }

    @XmlTransient
    public List<EventInfo> getEventInfoList() {
        return eventInfoList;
    }

    public void setEventInfoList(List<EventInfo> eventInfoList) {
        this.eventInfoList = eventInfoList;
    }
    
}
